package com.lilihub.miaosha.controller;

import com.lilihub.miaosha.common.CodeMsg;
import com.lilihub.miaosha.common.Result;
import com.lilihub.miaosha.domain.MiaoshaUser;
import com.lilihub.miaosha.domain.OrderInfo;
import com.lilihub.miaosha.service.GoodsService;
import com.lilihub.miaosha.service.MiaoshaService;
import com.lilihub.miaosha.service.OrderService;
import com.lilihub.miaosha.vo.GoodsDetailVo;
import com.lilihub.miaosha.vo.GoodsVo;
import com.lilihub.miaosha.vo.OrderDetailVo;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.util.resources.ga.LocaleNames_ga;

import java.security.acl.LastOwnerException;

/**
 * @BelongsProject: miaosha
 * @BelongsPackage: com.lilihub.miaosha.controller
 * @Author: LiYing
 * @CreateTime: 2021-04-28 15:30
 * @Description:
 */
@Controller
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private GoodsService goodsService;

    @Autowired
    private OrderService orderService;


    @Autowired
    private MiaoshaService miaoshaService;


    @RequestMapping(value = "detail")
    @ResponseBody
    public Result<OrderDetailVo> orderDetail(@RequestParam("orderId") long orderId,
                                         MiaoshaUser user){

        if (user == null){
            return Result.error(CodeMsg.USER_EMPTY);
        }

        OrderInfo orderInfo = orderService.getOrderById(orderId);

        if (orderInfo == null){
            return Result.error(CodeMsg.ORDER_EMPTY);
        }

        Long goodsId = orderInfo.getGoodsId();
        GoodsVo goods = goodsService.getGoodsByGoodsId(goodsId);

        OrderDetailVo vo = new OrderDetailVo();
        vo.setGoods(goods);
        vo.setOrderInfo(orderInfo);

        return Result.success(vo);

    }







}
